﻿@model IEnumerable<BTKERP.Model.Product>

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section AdditionalJS
{
    <script type="text/javascript">
        $(document).ready(function () {
            $("#productTable").dataTable(); 
        });

        function addNewProduct() {
            //$("#newProductDialog").dialog({width:'auto'});
            window.location = "/Product/Create";
        }

        function deleteItem(id) {
            if (confirm("Are you sure to delete?")) {
                $.ajax({
                    url: "/Category/Delete",
                    type: "POST",
                    data: "id=" + id,
                    success: function (data) {
                        if (data && data.result == "1") {
                            document.location.reload();
                        }
                        else {
                            this.error();
                        }
                    },
                    error: function () {
                        alert("Delete Failed! Please try again later!");
                    }
                });
            }
        }

        function edit(id) {
            $("#tid").val(id);
            $("#tname").val($.trim($("#name" + id).text()));
            $("#tdesc").val($.trim($("#desc" + id).text()));
            SelectItem("groups", $.trim($("#group" + id).text()));
            $("#editorTable").show();
        }

        function cancelEdit() {
            $("#editorTable").hide();
        }

        function saveChange() {
            if (confirm("Are you sure to update?")) {
                var data = $("#editForm").serialize();
                $.ajax({
                    url: "/Category/Edit",
                    type: "POST",
                    data: data,
                    error: function () {
                        alert("Update Failed!");
                        cancelEdit();
                    },
                    success: function (data) {
                        if (data && data.result == "1") {
                            document.location.reload();
                        }
                        else {
                            this.error();
                        }
                    }
                });
            }
        }
    </script>

}
<h2>Product</h2>

<input type="button" value="Create New" class="btn btn-green" onclick="addNewProduct();" />

<div id="newProductDialog" title="Products" style="display: none; ">
    <p>Add Product</p>
    <table class="editor stylized">
        <thead>
           <tr>
        <th>
            Code
        </th>
        <th>
            Name
        </th>
        <th>
            PhysicalBarcode
        </th>
        <th>
            PackBarcode
        </th>
        <th>
            Description
        </th>
        <th>
            Category
        </th>
        <th>
            Physical Unit
        </th>
        <th>
            Pack Unit
        </th>
        <th>
            #PerPhysical
        </th>
        <th>
            PhysicalWeight
        </th>
        <th>
            PackWeight
        </th>
        <th>
            PhysicalSalePrice
        </th>
        <th>
            PackSalePrice
        </th>
     </tr>
        </thead>
        <tbody>
            <tr>
                <td>
                    <input type="text" class="W50" id="code" name="code" />
                </td>
                <td>
                    <input type="text" class="W50" id="productname" name="productname"/>
                </td>
                <td>
                    <input type="text" class="W50" id="physicalBarCode" name="physicalBarCode"/>
                </td>
                <td>
                    <input type="text" class="W50" id="packbarcode" name="packbarcode"/>
                </td>
                <td>
                    <input type="text" class="W50" id="desc" name="desc"/>
                </td>
                <td>
                   @* <input type="text" class="W50" id="category" />*@
                   @Html.DropDownList("category")
                </td>
                <td>
                    <input type="text" class="W50" />
                </td>
                <td>
                    <input type="text" class="W50" />
                </td>
                <td>
                    <input type="text" class="W50" />
                </td>
                <td>
                    <input type="text" class="W50" />
                </td>
                <td>
                    <input type="text" class="W50" />
                </td>
                <td>
                    <input type="text" class="W50"/>
                </td>
                <td>
                    <input type="text" class="W50" />
                </td>
            </tr>
        </tbody>
    </table>
</div>
<table id="productTable" class="display stylized">
<thead>
    <tr>
        <th>
            Code
        </th>
        <th>
            Name
        </th>
        <th>
            PhysicalBarcode
        </th>
        <th>
            PackBarcode
        </th>
        <th>
            Description
        </th>
        <th>
            Category
        </th>
        <th>
            Physical Unit
        </th>
        <th>
            Pack Unit
        </th>
        <th>
            # Pack in Physical
        </th>
        <th>
            PhysicalSalePrice
        </th>
        <th>
            PackSalePrice
        </th>
       
        <th></th>
    </tr>
</thead>
<tbody>
@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Code)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.PhysicalBarcode)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.PackBarcode)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Description)
        </td>
        <td>
            @BTKERP.MVCWeb.AppCode.DataRefHelper.GetCategoryById(item.CategoryId)
        </td>
        <td>
             @BTKERP.MVCWeb.AppCode.DataRefHelper.GetUnitById(item.PhysicalUnitId)
        </td>
        <td>
             @BTKERP.MVCWeb.AppCode.DataRefHelper.GetUnitById(item.PackUnitId)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.NumberPerPhysical)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.PhysicalSalePrice)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.PackSalePrice)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
            @Html.ActionLink("Details", "Details", new { id=item.Id }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.Id })
        </td>
    </tr>
}
</tbody>
</table>


